package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsSearchHistory;
import com.qf.service.DtsSearchHistoryService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * projectName:workspace_6
 * author:hyn
 * time:2021/12/1 11:39
 * description:搜索历史
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/admin/history")
public class AdminHistoryController {
    @Autowired
    private DtsSearchHistoryService searchHistoryService;
    //搜索历史
    @RequestMapping("list")
    public Object list(String userId, String keyword,
                       @RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                       @RequestParam(name = "limit",required = false,defaultValue = "20") Integer limit,
                       @RequestParam(name = "sort",required = false,defaultValue = "add_time") String sort,
                       @RequestParam(name = "order",required = false,defaultValue = "desc") String order
    ){
        IPage<DtsSearchHistory> users = searchHistoryService.findAll(keyword,userId,limit,page,sort,order);
        HashMap<String, Object> data = new HashMap<>();
        data.put("total",users.getTotal());
        data.put("items",users.getRecords());
        return ResponseUtil.ok(data);
    }
}
